﻿#ifndef INTER_INTERPRETER_H
#define INTER_INTERPRETER_H

#include <fstream>
#include <vector>
#include <map>

using namespace std;
fstream fa;//虚拟机代码 NOLINT
fstream fa1;//源文件 NOLINT
ofstream fa2;//输出结果 NOLINT
const int cxMax = 200;
enum class fct {
    LIT, LOD, STO, CAL, INT, JMP, JPC, ADD, SUB, MUL, DIV, RED, WRT, RET,
};
int cx;

class Interpreter {
private:
    fct f;//虚拟机代码指令
    int l;//引用层和声明层的层次差
    int a;//根据f的不同而不同

public:
    Interpreter() = default;

    Interpreter(fct f, int l, int a) {
        this->f = f;
        this->l = l;
        this->a = a;
    }

    static void interpret();

    static void read();
};

int gen(fct x, int y, int z);

fct strToFct(const string &str);

string fctToStr(fct f);

int base(int l, const int *s, int bp);

vector<Interpreter> code;//存放虚拟机代码的容器

const map<fct, string> fctMap = {//NOLINT
        {fct::LIT, "LIT"},
        {fct::LOD, "LOD"},
        {fct::STO, "STO"},
        {fct::CAL, "CAL"},
        {fct::INT, "INT"},
        {fct::JMP, "JMP"},
        {fct::JPC, "JPC"},
        {fct::ADD, "ADD"},
        {fct::SUB, "SUB"},
        {fct::MUL, "MUL"},
        {fct::DIV, "DIV"},
        {fct::RED, "RED"},
        {fct::WRT, "WRT"},
        {fct::RET, "RET"},
};

int yyparse();

int yyrestart(FILE *input_file);

#endif //INTER_INTERPRETER_H
